#include<iostream>
#include<vector>
using namespace std;
const int maxn=50010;
int N,pre[maxn],in[maxn];
vector<int> ans;
struct node{
    int data;
    node* lchild=NULL;
    node* rchild=NULL;
};

node* create(int preL,int preR,int inL,int inR){
    if(preL>preR || inL>inR) return NULL;
    int k=pre[preL];
    int idx;
    for(int i=inL;i<=inR;i++){
        if(in[i]==k){idx=i;break;}
    }
    node* root=new node;
    root->data=k;
    root->lchild=create(preL+1,preL+idx-inL,inL,idx-1);
    root->rchild=create(preL+idx-inL+1,preR,idx+1,inR);
    return root;
}
void postorder(node*root){
    if(root==NULL) return;
    if(root->lchild!=NULL){postorder(root->lchild);}
    if(root->rchild!=NULL){postorder(root->rchild);}
    ans.push_back(root->data);
}
int main(){
    //freopen("in.txt","r",stdin);
    scanf("%d",&N);
    for(int i=1;i<=N;i++){
        scanf("%d",&pre[i]);
    }
    for(int i=1;i<=N;i++){
        scanf("%d",&in[i]);
    }
    node* root=new node;
    root=create(1,N,1,N);
    postorder(root);
    printf("%d",ans[0]);
}
